<template>
	<view class="content">
		<!-- 提现 开始 -->
		<view class="title">
			<view class="mony">
				{{UserAccount.amount}}
			</view>
			<view class="name">
				当前余额(元)
			</view>
			<view class="btn-tx act" @click="txBtn"  v-if="withdrawOpen==0">
				提现
			</view>
			<view class="btn-tx" @click="txBtn"  v-else>
				提现
			</view>
		</view>
		<!-- 提现 结束 -->
		<!-- 用户须知 开始 -->
		<view class="list">
			<view @click="mxBtn" class="list_title" style="margin-top: 20rpx;">
				<view class="left">
					提现明细
				</view>
				<image src="../../../static/icon/right.png" mode=""></image>
			</view>
		</view>
		<!-- 用户须知 结束 -->
		<is-login v-on:childClick='listenToClose' v-on:childClickAgain='listenToCloseAgain' v-if="isLogin==0"></is-login>
	</view>
</template>

<script>
	import isLogin from '../../../components/isLogin.vue'
	import {
		uniIcons
	} from '@dcloudio/uni-ui'
	export default {
		components: {
			uniIcons,
			isLogin
		},
		data() {
			return {
				flag: true,
				isLogin: 1,
				UserAccount: {},
				amount_rebate: null,
				score_rebate:null,
				withdrawOpen:0
			}
		},
		onLoad() {
			this.imgUrl = this.$imgUrl
			if (!uni.getStorageSync('openid')) {
				this.isLogin = 0
			} else {
				this.getMoneyInfo()
				this.getOpen()
				// this.getSomeMoneyInfo()
			}
		},
		onPullDownRefresh() {
			uni.showToast({
				icon: 'loading',
				title: '加载中',
			});
			setTimeout(() => {
				this.getMoneyInfo(() => {
					uni.hideLoading()
					uni.stopPullDownRefresh()
				})
				tihs.getOpen()
				// this.getSomeMoneyInfo()
			}, 1000)
		},
		methods: {
			// 提现开关
			getOpen(){
				let that = this
				var data = {
					openid: uni.getStorageSync('openid')
				}
				this.$myRequest.post(this.$api.distribution.withdrawStatus, data).then(res => {
					if (res.code == '200') {
						this.withdrawOpen =  res.data.withdraw_open
					} else {
						uni.showToast({
							title: res.msg,
							icon: "none"
						})
					}
				})
			},
			getMoneyInfo(callback) {
				let that = this;
				var data = {
					openid: uni.getStorageSync('openid')
				}
				this.$myRequest.post(this.$api.mine.getUserAccount, data).then(res => {
					if (res.code == '200') {
						that.UserAccount = res.data
						callback && callback()
					} else {
						uni.showToast({
							title: res.msg,
							icon: "none"
						})
					}
				})
			},
			// 纍計應盡
			getSomeMoneyInfo() {
				let that = this;
				var data = {
					openid: uni.getStorageSync('openid')
				}
				this.$myRequest.post(this.$api.distribution.getTotalRebate, data).then(res => {
					if (res.code == '200') {
						that.amount_rebate = res.data.amount_rebate
						that.score_rebate = res.data.score_rebate
					} else {
						uni.showToast({
							title: res.msg,
							icon: "none"
						})
					}
				})
			},
			// 跳转提现页面
			txBtn() {
				let that = this;
				if(that.withdrawOpen==0){
					uni.showToast({
						title:'提现暂未开启',
						icon:'none'
					})
				}else{
					uni.navigateTo({
						url: '../withdrawDeposit/index'
					})
				}
				
			},
			// 跳转提现明细页面
			mxBtn() {
				uni.navigateTo({
					url: '../particulars/index'
				})
			},
			listenToClose(msg) {
				this.isLogin = msg
			},
			listenToCloseAgain() {
				this.getMoneyInfo();
				tihs.getOpen()
				// this.getSomeMoneyInfo()
			},
		}
	}
</script>

<style lang="scss" scoped>
	.act{
		background-color:  #F1F1F1!important;
		color: #989898!important;
	}
	.showtag {
		margin-top: 20rpx;
	}

	// 动画
	.arrowTransform {
		transition: 0.2s;
		transform-origin: center;
		transform: rotateZ(90deg);
	}

	.arrowTransformReturn {
		transition: 0.2s;
		transform-origin: center;
		transform: rotateZ(0deg);
	}

	.content {
		width: 690rpx;
		margin: 0 auto;

		.title {
			width: 689rpx;
			// height: 258rpx;
			background: #FFFFFF;
			box-shadow: 0px 2rpx 10rpx 0px rgba(90, 96, 105, 0.14);
			border-radius: 10rpx;
			text-align: center;
			padding-bottom: 50rpx;

			.mony {
				color: #294D7C;
				font-size: 50rpx;
				padding-top: 40rpx;
				margin: 40rpx 0 26rpx 0;
			}

			.name {
				color: #333333;
				font-size: 22rpx;
				margin-bottom: 28rpx;
			}

			.btn-tx {
				width: 360rpx;
				line-height: 66rpx;
				background: #294D7C;
				border-radius: 4rpx;
				color: #fff;
				margin: 0 auto;
			}
		}

		.list {
			color: #333333;
			font-size: 26rpx;

			.list_title {
				height: 84rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;
				border-bottom: 2rpx solid #E5E5E5;

				image {
					width: 30rpx;
					height: 30rpx;
				}
			}

			.name {
				font-size: 22rpx;
				font-family: Source Han Sans CN;
				font-weight: 400;
				color: #666666;
				line-height: 30rpx;
				margin-top: 8rpx;

				text {
					margin: 0 8rpx;
					color: #294D7C;
				}
			}
		}
	}
</style>
